//axios二次封装
import axios  from "axios";
//引入进度条
import { useUserStore } from '../store/user.js'

const requests = axios.create({
    timeout:5000,
    baseURL:"/api"
})

//请求拦截器
requests.interceptors.request.use((config)=>{
    const userStore = useUserStore()
    let token = userStore.token
    if (token) {
        config.headers['Authorization'] = token
    }
    return config;
});
//响应拦截器
requests.interceptors.response.use((res)=>{
    return res.data
},(error)=>{
//截至promise
    return Promise.reject(new Error('faile'));
});


export default requests; 